package com.yunduansing.core.controller;

import javax.servlet.http.HttpServletRequest;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.yunduansing.core.model.LogModel;
import com.yunduansing.core.service.LogService;
import com.yunduansing.core.utils.ResultUtil;

@Controller
@RequestMapping("/hello")
public class HelloController {
	private LogService logService;
	private ApplicationContext context;
	
	public HelloController(){
		context=new ClassPathXmlApplicationContext("beans.xml");
		logService=(LogService) context.getBean("logService");
	}
	
	@RequestMapping(method=RequestMethod.GET)
	public String index(){
		com.yunduansing.core.aop.Math math=context.getBean("math", com.yunduansing.core.aop.Math.class);
		math.add(1, 2);
		return "hello/index";
	}
	
	@RequestMapping("/index/{id}")
	public String detail(HttpServletRequest req,@PathVariable(value="id") int id){
		req.setAttribute("id", id);
		return "hello/detail";
	}
	
	@RequestMapping(value="/save",method=RequestMethod.POST)
	public @ResponseBody ResultUtil save(LogModel m){
		return logService.save(m);
	}
}
